package com.tjmntv.tj.myapplication.demo7

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.tjmntv.tj.myapplication.R
import kotlinx.android.synthetic.main.fragment_video.*

/**
 * A simple [Fragment] subclass.
 * Use the [VideoFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
private val videoUrls: List<String> = listOf<String>(
    "https://vd3.bdstatic.com/mda-jmwifhxacbra71eh/v1-cae/sc/mda-jmwifhxacbra71eh.mp4?v_from_s=hkapp-haokan-tucheng&auth_key=1629184300-0-0-f678b30920a092313ebb704e4cb9bd30&bcevod_channel=searchbox_feed&pd=1&pt=3&abtest=",
    "https://vd3.bdstatic.com/mda-jmwifhxacbra71eh/v1-cae/sc/mda-jmwifhxacbra71eh.mp4?v_from_s=hkapp-haokan-tucheng&auth_key=1629184300-0-0-f678b30920a092313ebb704e4cb9bd30&bcevod_channel=searchbox_feed&pd=1&pt=3&abtest=",
    "https://vd3.bdstatic.com/mda-jmwifhxacbra71eh/v1-cae/sc/mda-jmwifhxacbra71eh.mp4?v_from_s=hkapp-haokan-tucheng&auth_key=1629184300-0-0-f678b30920a092313ebb704e4cb9bd30&bcevod_channel=searchbox_feed&pd=1&pt=3&abtest=",
    "https://vd3.bdstatic.com/mda-jmwifhxacbra71eh/v1-cae/sc/mda-jmwifhxacbra71eh.mp4?v_from_s=hkapp-haokan-tucheng&auth_key=1629184300-0-0-f678b30920a092313ebb704e4cb9bd30&bcevod_channel=searchbox_feed&pd=1&pt=3&abtest=",
    "https://vd3.bdstatic.com/mda-jmwifhxacbra71eh/v1-cae/sc/mda-jmwifhxacbra71eh.mp4?v_from_s=hkapp-haokan-tucheng&auth_key=1629184300-0-0-f678b30920a092313ebb704e4cb9bd30&bcevod_channel=searchbox_feed&pd=1&pt=3&abtest="
)

class VideoFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_video, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        videoViewPager.apply {
            adapter = object : FragmentStateAdapter(this@VideoFragment) {
                override fun getItemCount() = videoUrls.size

                override fun createFragment(position: Int) = PlayerFragment(videoUrls[position])
            }
            offscreenPageLimit = 5
        }
    }
}